#1,导入requests
import time

import requests

from config.config import *


#3，构造富文本消息
#"tag":"text" 表示文本内容
#"tag":"a" 表示的超链接
#"href":"https://baidu.com"表示超链接的跳转地址
def send_feishu_message():
    message_data = [
        [
            {
                "tag": "text",
                "text": f'项目名称:{PROJECT_NAME}'
            },
            {
                "tag": "a",
                "text": "点击查看",
                "href": REPORT_PATH
            }
        ],
        [
            {
                "tag": "text",
                "text": f'执行时间:{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}'
            }
        ],
        [
            {
                "tag": "text",
                "text": "执行时间:2025-09-15 10:00:00"
            }
        ],
        [
            {
                "tag": "text",
                "text": "详细信息"
            }
        ],
        [
            {
                "tag": "text",
                "text": "测试结果:成功",
                "href":"https://www.baidu.com"
            }
        ],
    ]
    # 构建最终的消息体
    payload = {
        "msg_type": "post",
        "content": {
            "post": {
                "zh_cn": {
                    "title": "星云ERP项目接口测试报告",
                    "content": message_data
                }
            }
        }
    }
    #发送消息的开关，默认为True
    if FEISHU_SWITCH:
        #5,发送消息
        response = requests.post(WEBHOOK, json=payload)
        return response




